Lots of individual fixes

I tried using nin to write a small demo. This pull request fixes some of the issues I discovered.