Fixed some bugs introduced by previous commit.