Add logic to build a grant matrix function