Code cleanup in layout code