Major refactoring
Finished refactoring