added a more reliable fix to toMS()