Fixed bug and added testcase script