get_next_dir function added