Fix obvious compiler and analyzer warnings/errors

Please verify that these changes have not broken anything that was not already broken.