refactory QueryFactory