Fixed bugs and corrected test cases