updated main.R to save files correctly