Fixing a bug in createMiddleware