Check for parent not being None

We can get a function here as well which will have no parent, see
issue #25.
Merge pull request #26 from nijel/master

Check for parent not being None