OK, so some more testing and I've made if more robust. The permissions on the appxmanifest.xml file weren't being reset correctly so I fixed that.
I also tested a Windows update that installed a new version of the CBS package and it failed, so I've added another option to revert back to the...