reworking extraction. write to tmpname then rename