Restructure UI code a little.