Add reproducing test case for issue #215
Reimplement caching correctly for #215 and #223
Add back some comments lost in the revert