basic motion detection function