changed analyze query to function