Moved query functions to query class