refactor querys