replace tempfile with StringIO