cleaned up merge code