refactored next_move method