Refactor main source into separate files