Added null checks to fix issue #59