Fixed the index race condition