Cleaned up and refactored the UI code

Basically all the changes