Fix some bugs in 39471e0c672e8d0d7717b424473e70052a061b8e.