started writing msd function