Refactor doCX to a separate module

This function was almost identically repeated in two modules.

Change-Id: Ic654b35837f16e7234c38b75a8f380a829baf697
Merge "Refactor doCX to a separate module"