added thread sync