Fixed bugs found by the cppcheck