Fixed a bunch of cppcheck warnings