clean up middlware running

also assert that middleware are functions