Fix issues found by code inspection