updated and refactored move logic