refactoring automerge functions to make them more flexible