added more logic to ensure directories exist before symlinking