Expanded main method (for experimenting). Minor refactoring.