*************IMPORTANT************************
Fixed race condition bug