Change var names, improve SQL query, add mean & stdev calculation