Major refactoring stage 2