Fixed possible race condition.