Refactored query functions
Refactored test file structure and code