change recursive flag to depth parameter