serious code refactoring part 3