Break out some of the code in main
Split level-specific state from global state
Place level creation in separate module