Fix a possible race condition