generateSQL method
Minor refactoring