Improve patchIfNeeded

Addresses #50