Ran CppCheck, fixed a bunch of errors and warnings.

I feel purdy.