added writefile functionality