Fixed a race condition