Refactor input processing in main program