Migrated code to a background worker with cancel.