serious code refactoring part 2