passes all tests. now need to improve speed, mostly indexing of nodes for faster lookup