improvements to handling of agencyCode