big refactoring part 1