Cleaned up and fixed potential null pointers
Merge pull request #1 from yorn/master

Cleaned up and fixed potential null pointers