Cleaned up SQL statement generation.