Improved test suite and fixed bugs