Major refactoring part 2