The functions calls bis_fnc_returnChildren on the "depth - 1" level, even if the current depth is 0. This unnecessarily increases the script run time.
Also, the _lastOnly parameter works the other way around, so it should be _allTiers (or something like this), but upgrading its description would be enough.
https://community.bistudio.com/wiki/BIS_fnc_returnChildren
edit: also using set instead of pushback