Refactor QueryController