further refinement of the layout module and some cleanup