Added a few extra null checks as part of issue #13