new version with distance