move most of the logic from main into process_args