Improved thread safety

Change-Id: I801711ea9428e1fa5feab1d4dc754972909548ab