Added lots of new sql, reporting, and refactoring