Improved layout code