overhauled middleware