Merge

This is a PR based off of #579 - but rebased on latest and including an extra commit to tweak the merge logic. This PR would supersede #579.