[LCG] Refactor the duplicated code I added in my last commit here into