started major refactor, tests are currently broken