Looks work now

* Fixed a stupid DFS issue
* caching subloops, which may result in better performance