added locks and temp logic