Function for merging nodes was implemented.