added locking to query builder