Cleanups/warning fixes

Huge bunch of various fixes and cleanups to get rid of warnings on OS X and Linux.