added check for directory to exist to avoid error