wow that took a lot of refactoring