Refactored some of the layout code.