Fix struct encoding

There was accidentally an extra empty dict.  Also, reduce the scope of a local
variable.