Dry up tests and refactor