Section 7. (a) A court which has jurisdiction pursuant to section two may decline to exercise its jurisdiction at any time prior to making a custody determination upon finding that its assumption of jurisdiction would be (i) violative of the purposes of this chapter; or (ii) would be based upon the illegal or otherwise wrongful conduct of a party; or (iii) would constitute an inconvenient forum and that a court of another state would constitute a more convenient forum.
(b) A court may decline jurisdiction for any of the reasons set forth in paragraph (a) upon motion of a party or of any representative of the child entitled to appear before the court or upon the court's own motion.
(c) In order to determine whether it is the appropriate forum, a court of the commonwealth may, in its discretion, at any time during the pendency of the custody proceeding, communicate and exchange information with a court or courts of any other relevant jurisdiction.
(d) For the purposes of this section, a court may consider the following factors:
(1) whether another state is or recently was the child's home state;
(2) whether another state has a closer connection with the child and his family or with the child and one or more of the contestants;
(3) whether more substantial evidence concerning the child's present or future care, protection, training, and personal relationships is available or whether such evidence is more readily available in another state;
(4) whether the parties have agreed on another forum which is not less appropriate; and
(5) whether the exercise of jurisdiction by a court of the commonwealth would contravene any of the purposes of this chapter.
(e) If a court shall find that a court of another jurisdiction is or may be a more appropriate forum under the terms of this chapter for the adjudication of the custody proceeding, it may do one or more of the following:
(1) dismiss the proceeding with or without prejudice;
(2) vacate any order or judgment already entered;
(3) stay the proceeding upon condition that a custody proceeding be initiated or prosecuted in another state in a timely manner or upon any other condition that the court might deem just;
(4) retain jurisdiction over any action to which the custody proceeding is incident, while declining to render a custody determination;
(5) enter such temporary order or orders as may be required, in the court's discretion, pursuant to clause (ii) of paragraph (3) of section two;
(6) assess any or all of the costs of the custody proceeding in this state, having due regard for the purposes of this chapter, including the reasonable travel and other expenses of any party and his or her witnesses, the reasonable attorneys' fees of any party, the costs of the court's communications and information exchanges with other courts and the fees and costs of any person entitled to appear before the court as the representative of a child;
(7) assess sanctions against any party whom the court finds has engaged in illegal or otherwise wrongful conduct;
(8) enter any other order or judgment which may be meet and just under the circumstances of the case.
(f) A court shall communicate to the court of any other relevant jurisdiction any determination or finding made pursuant to this section.