Moved some setup in main to its own function