Fixes some of the bugs introduced in the last commit.