much improved sql queries