tweaks to the middleware to be more generic