Modified write file to be better