Check for null parent in recurseElement

The check is done elsewhere in this method, it should be done here as
well