NPE fixes, added Null checks

Error: http://pastie.org/9383324 for commit: a491888
Error: http://pastebin.com/sqiqfjin for commit: 462cfb0
Error: http://pastebin.com/9J0qAWTh for commit: d22f314