Fix potential threading issue