added thread lock synchronization