Lots of fixing of layout code