bug fixes and test cases