Use libdispatch so UI doesn't hang. Minor code cleanup.