refactor of sql query functions