Move the framework loading code into its own XCmd and add more error checking.