Add tests, address issues raised by testing.