bug fixes and some new tests.