Fixed writing to incorrect directories