add checks for directory existence