moved erase_local_folder into a method to reduce duplication. credit @mm53bar.