Check for nil pointer. Fixes #20

Pull request for issue #20