Fix bugs reported by test cases.