added locking mechanism