More incremental refactoring of main().