Simplifying paths. (removing unused nodes.)