modified version n adi code