Fixes to SQL script