fixed bug and added test case