Modularize main to make it easier to test