Refactor backend structure