Final working version of main file...handles new appending and overwriting files