Bunch of clean-up flagged by static code analysis.  Some refactoring to reduce duplicate code, removing unused stuff, etc.