Refactor redundant input processing loop.