Fix some bugs in the previous commit