Test suite and bug fixes