corrected the merge of node problem but still can be improved