Fixed middleware not returning generator function