Make cppcheck happy. (normally we assume malloc does not fail.)
Remove unused variables
Remove globals