Refactored general gui logic into GuiUtil.