added null guards
Merge pull request #535 from adamralph/null-guards

added null guards