Fixed some issues with the SQL script generation