Add tests and fix minor errors.