fix some critical issues, acting on code analysis