Fix some bugs in the previous change.