adding testcase and fixing bug