Massive refactoring into separate files and interfaces