QueryLock refactoring