[Refactor] Refactored the horiExcg function.