Feature/query refactor