Fix for concurrency issues

Updated to handle concurrency