Fixed critical bugs.

Fixed critical bugs.