Optimizing TriggerFactory code