updated generating_where_clause function to generate accurate query