cleaned up motion detection