Fixing various complaints by the clang compiler's static analysis

Some low priority bugs were found and fixed here. Mostly just elimination of dead code and added more NULL pointer checks.

More deletions than additions as usual