Added these cleaning code to avoid race condition.