Reorganize main code into separate files.