Added missing null checks and tests
Merge pull request #1 from pmacn/nullchecks

Added missing null checks and tests