Octahedral versus trigonal prismatic rearrangements in MoF6 and WF6 derivatives