UI coding changes

Refactored the UI for less code duplication.