Clean up ns declarations, more idiomatic code

I'm still working on this, it's not quite ready yet.