Can you put this and the following methods in a middleware module or base class or something to DRY this and the other middleware out?