code refine for entity