rearranged middleware