Can this be updated and moved to utils and used from both diff & metrics. I believe metrics.py also has the same method.