Add tests, tidy up code, add README.