Refactored input handling