fix middleware order issue