refactored parse_dir