Make test shim replacer more error resistant