Separate functions have been implemented for merging, pruning and
backtracing