Cleaned up and refactored the UI code

Initial pull request with some cleanup code to refresh my Git memory