add `flat` parameter as opposite of `deep`