Added some pointer checks as discussed in issue #36