new sql script, refactoring