big refactoring in progress