An assload of null checking for keys

also went through and cleaned up some code issues, redundant casts,
unnecessary local variables and the like
Merge pull request #468 from hilburn/master

A load of null checking for keys