adding null checks

Added a few null checks in spots that where tripping me up. 

There are probably a lot more to be added to try and fix stupid.