contains method works at arbitrary depth