fixed performance issue with StringIO.