merged bug fixes, added test cases