Clean up code in input_handler