Revert "Revert "Significant UI code restructuring""

This reverts commit 4017afe2ce13c30221c519587aa1eb45b2c00138.