Fixed race condition.
Merging upstream