improve middleware chain for embeded app