initial refactoring, wip