changed merge code, not tested