Fixed race conditions.