added middleware, switch for view rendering