Enabled more queries

Moved a lot of SQL stuff to models
Redesigned application structure