cleaned up process_command() the best I could