Query initialization refactoring