big refactor - part 1