fixes to ad code