Factor out patching and implement unstage_patch
Calculate offsets correctly
Implemented unstaging of selection