finished query function, i think this works