Fix bug where trees would be skipped/duplicates would be generated