Improved test suite, fixed some small bugs.