Fix several critical issues