Fixed several bugs in last commit.