Bugfixing sql being nil