Fixed some bugs in the previous commit.