clean up merge code a bit