Implemented around 70 unit tests.
Improved other tests.
Fixed bugs caught by tests.