Streamlined code, bugfix

Made code much more efficient (thx @schriftgestalt)
Fixed a bug where no inflection nodes would be inserted on open paths
under certain circumstances.