Handle deeply-nested structures correctly.

Closes #1.