Refactor index

Simplify the index by pushing some logic into the models, controller, and routes.