Fix handling of `primary_ais`, add test