Fixes sql issues