Fixed bugs and test cases.