Code analysis

Fixed several code analysis issues.