a tiny optimization at motion_detection function