fixing bugs in sql operations