Made major refactoring