Major overhaul of the coding behind layout.