Add tests and clean up a little