merge bug fixes and unit tests