Add tests and more comments