refine some codes