Use threads to avoid stalling GUI.