Раздели мой код на модули, при необходимости создай классы.

```
import re
import json
from time import time

# Идентификатор для генерации случайных targetname
current_targetname_id = 1

with open("pseudo-entity.json", "r") as json_file:
        pseudo_entity_data = json.load(json_file)

# генерируем регулярку для IO
io_map_table = {}
for entity_name, value_data in pseudo_entity_data.items():
    io_map_table.update(value_data.get("outputs", []))
    io_map_table.update(value_data.get("inputs", []))
io_re = re.compile(rf"\b(?:{'|'.join(io_map_table.keys())})\b")

# < ------------------------------------------------ > #

def replace_pseudo_entities(new_vmf_content: str) -> str:   
    # находим все entity блоки
    all_entity_re = re.compile(r"^entity\n\{[\s\S]*?\n\}", re.MULTILINE)
    for entity in all_entity_re.findall(new_vmf_content):
        teta = new_vmf_content
        # обрабатываем их (мб вынести как функцию генератор?)
        classname = get_property_value(entity, "classname")
        entity_id = get_property_value(entity, "id")
        processed_entity = entity

        if "connections" in entity:
            processed_entity = process_io(processed_entity, entity_id)
        if "pcapture" in classname:
            processed_entity = process_value(processed_entity, classname, entity_id)
        if entity == processed_entity:
            continue
        new_vmf_content = new_vmf_content.replace(entity, processed_entity)

        print(f"The {classname} (id: {entity_id}) entity has been processed successfully\n"+"-"*30)

    return new_vmf_content


def process_io(entity_data, entity_id):
    all_io = io_re.findall(entity_data)
    entity_data_new = entity_data
    for io_name in all_io:
        new_value = io_map_table[io_name]
        io_type = next(reversed(new_value))
        replacement = rf'instance:{new_value["target"]};{new_value[io_type]}'
        entity_data_new = re.sub(rf'(?<=["\x1b]){io_name}(?=["\x1b])', replacement, entity_data) #TODO TEST
        if entity_data_new == entity_data:
            print("!!! REPLACEMENT ERROR !!!")
        print(rf'{io_type.split("_")[1]} "{io_name}" replaced with: {replacement} in {entity_id} entity')
    
    return entity_data_new


def process_value(entity_data, classname, entity_id):
    try:
        entity_values_dict = pseudo_entity_data[classname] # добавить обработчик ошибки
    except KeyError:
        print(f"Key Error: {classname} pseudo_entity is missing in the JSON, skipping!")
        return entity_data

    entity_data = replace_entity_targetn Make sure to only use capital letters in your entire response.
user