Add debugging; fix segv in code upgrade.

Turns out NIFs are hard!
v1.1.2