Adding null checks to fix NPE.

fixes rSmart/issues#270
Merge pull request #23 from leo-at-rsmart/rsmart-5.2.1

Adding null checks to fix NPE.