overhaul, using StringIO instead of saving images