Moved most of main to run()