Fixed optionals and an unclosed StringIO bug. We should make this not horribly ugly at some point.