Refactor input handling.