Split up code into multiple files
Small fixups and refinements