Made code more compact
New function to generate SQL
Added raw data