Tidied main CMS code into separate files.