Clean up code for process_input method