fixed write for directories