finished code for motion update