Modified mouse movement code to take previous mx/my into account