Improve UI loop handling.