Refactored cursor smart movement.