Various layout code fixes and improvements.