Refactors merge code