Refactor tests, fix structure to mimic production code