Implement Tiangang Yin's ifCosWeighted workflow