Refactored UI code to run after variables are loaded so that this information can be retrieved before the UI is constructed