Refine some code