Refactored toggle_ui