your problem is here:
"This helper function should build and return a trigger depending on its type. It also keeps track of triggers and names in a map."
your function does not keep track of them in a map (or else called dictionary).