Refactor; revise tests.