Fixed bug with middleware