Improve UI loop handling.

Create and destroy the UI refresh loop as needed. Only ever have one loop running at a time.