Fixed a few crucial bugs.