Cleaned up the SQL and added comments