MAJOR fixes. Rewrite of relayout.