test cases and bug fixes