fix bug in middleware chaining