remove waste duplicated code
added saveAsTextFiles and saveAsPickledFiles