Bug fix, all test cases pass.