Changed how sql is constructed