Refine code structure