Implemented Tarjan's algorithm for removing dead-end nodes.

 - Previous two pass algorithm didn't work optimally in all cases.
 - Tarjan's is a single pass, and ~2x the speed.
 - Added extra tests.