updated tests and a bit of restructuring