Some cleanup for layout code