Made array wrap around action conditional to enable both global and per function middleware