Could maintain an Int array of IDs to check with, which would take these concerns out of the equation. You can do a reverse of this here as well to find the raw ref. Either or. Here is how to get those IDs. Old Post now I guess so just dropping this here in case it gives you help or ideas
Int Function FetchID(Form Core,Formlist ToScan)
Bool Workable = Core as Bool && ToScan as Bool
Int Total = Workable as Int * ToScan.GetSize()
Bool Done = !Total as Bool
If !Done
Form[] Sweep = ToScan.ToArray()
Int Kind = 61 + (Core.GetType() == 43) as Int
Int Digit
While !Done && Digit < Total
Done = Sweep[Digit] as Bool && Sweep[Digit].GetType() == Kind && (Sweep[Digit] as ObjectReference).GetBaseObject() == Core
If Done
Return Sweep[Digit].GetFormID()
EndIf
Digit += 1
EndWhile
EndIf
Return 0
EndFunction