Refactor input processing.