refactor and optimize the move function