Fix additional performance issues found by cppcheck