Fixes potential race condition.