Tidy code and simplify tests