more minor refactoring to main().