Refactored the common ESC routines