Updated to allow StringIO objects