Refactored code for better sql script generation.