Even more bug fixes and unit tests.