Fixed directory error, Added error handling