Minor optimisations to the motion detection algorithm