added prune utility for vertices of degree 1 and 2