Making the various tempfile functions more efficient