Reorganize some ui code.