updated sql, comments in code