Move directory check/creation to more appropriate location