Bug fix, test cases pass.