added test case and bug fix