Mike fixed db query functions