Nice job factoring this out and using it as middleware. :) We'll have to try this out for other modules as well.