fix sql queries