It would be nicer to add these nested checks as predicates to avoid a stack overflow, but this would be a much more complicated fix