Added main query functions, still refining