refine the code