complete overhaul of the final merge code