Added middleware, improved routes