Reduce duplicate code

do not duplicate the array walk, just check in the same for both cases