Refine code