refactory backend codes