refactor mostly done, testing
tests pass