Fixes to problems found with Codacy static analysis