Fix crash on statement cleanup

Fixes #159