Refactored movement detection