Fixed writing to directory