The cleanup is done in main thread