rearrange middleware