bug fixes and more tests