fix many many errors from static analysis.