Improve interface with c

Discovered this branch that I was working on last December -- now rebased on top of current master. It's mostly trivial fixes except perhaps the paragraph about refcounting bugs.