Bug 1096105: layout and optimization improvements