updated rmsd function