Added invalid directory error handling