Refactoring input handling