improved layout code