Starting to pull the stuff in main out into a separate function