refactored query functions