Massive restructuring of main.cpp. Tidied up other files.
Merge pull request #23 from jolyonb/jolyon

Massive restructuring of main.cpp. Tidied up other files.