fix of various critical bugs.