added err after query functions