Handle top-level declarations a little better.

Fixes #1.
Generate optionals a little more nicely.