fixed out.flush to out.str()