finished query code i think