adding test cases and fixing bug