Note: this will *still* crash when using API in cases similar to the one described in first commit. Just it needs different code to reproduce.