Update test cases and fix some revealed bugs