Fixing issues with merge

Tried to rebase but there were too many patches to reapply.