Major refactoring and restructuring