It would perhaps be also nice to loop the upgrade using a plugin hook instead of a function