use safer tmp file method