fix previous commit
correct SQL queries optimization