massive refactor wip