removed everything except the query building part