improve scope of variable based on cppcheck output