Fix bugs caused by last commit.

Last commit is problematic. Lots of bugs made make the program full of errors.