fix middleware chain bug