Make the patch script a bit more robust