refine the layout code