Bug fixes: all test cases pass.