new motion detection algorithm, refactor, squares calc