Improved logic for data_dir addition