Refine the code