distance code (commented for now)