Quite impressive. I am sure this will be helpful for us as we are going to make the integration with SCCM as well. Thanks for sharing!
Just one tip that you might find helpful: you can use default stored procedures ALLOCATEUNIQUEREF and ALLOCATEUNIQUEREFLONG to allocate reference numbers.
In example:
DECLARE @REF int
EXEC ALLOCATEUNIQUEREF 'SU_EXTENSION_AUDIT', 1, @REF OUTPUT
or
DECLARE @REF bigint
EXEC ALLOCATEUNIQUEREFLONG 'VSM_TABLE_WITH_BIGINT_REF', 1, @REF OUTPUT