Fixed a few critical bugs.