added locking code