mass refactor, tests