Add synchronization to properly check for completion of indexing