bug fixes and test fixes