General cleanup. Added static analysis option to scons
Fix a bunch of errors reported by clang's static analysis