fix SQL queries