refined motion detection. we have a memory leak