`takewhile` stops once the predicate is false, while `ifilter` just filters the results:
```python
>>> list(ifilter(bool, [True, True, False, True, False]))
[True, True, True]
>>> list(takewhile(bool, [True, True, False, True, False]))
[True, True]
```

I like the idea of using a hash for the layers. Will try to implement and report back