Nit: might be better merged with the condition above, the nesting is already deep enough.