performance optimizations using StringIO, v1.0.4