Add tests and make a minor bug fix.