General code clean up and refactoring

Starting to move queries into their own models, removed a lot of unused
code, moved helper functions into helper file, changed caching function
to built in Codeigniter driver