Tested writetofile, needs to be fixed