tried to implement merge. please check for correctness