extract function resolve_path
fix the path handling