refactor _iter_command_classes and iter_spider_classes