refine the code structure