Refactored some UI code.