fixed several critical errors and warnings.