refactoring movement logic