improved sql codes