Tried to fix some of the bugs.