fix sql issues