AEL breaks DST in CDR

Because of increasing number of employees in my company we were forced to move from 3-digit to 4-digit internal numbers. So process of choosing proper called ID for outgoing calls (E1 line) became quite complicated. That is why I decided to move this process to AEL as it was much easier to write (switch $CLID, pattern for low numbers, pattern for medium numbers, pattern for high numbers). But moving this to AEL resulted in posting stupid things in our MySQL CDR! Every outgoing call is posted with dst of _XXXX. .

From the telephony provider we have numbers 017xxxxxx00 to 017xxxxxx59 with ability to add extra digits at the end.

Below is an example what happens. Our employee who has number 2017 calls some external number (017xxxxxxxx). It is decided that since his number is betweek 2000 and 2059, he will use the short kind of caller ID.

-- Executing [017xxxxxxxx@Stuttgart_SIP:1] Goto("SIP/2017-08c128c0", "out_E1_test|017xxxxxxxx|1") in new stack
-- Goto (out_E1_test,017xxxxxxxx,1)
-- Executing [017xxxxxxxx@out_E1_test:1] Set("SIP/2017-08c128c0", "CLID="2017"") in new stack
-- Executing [017xxxxxxxx@out_E1_test:2] NoOp("SIP/2017-08c128c0", "Outgoing from 2017 to 017xxxxxxxx| determining proper caller id...") in new stack
-- Executing [017xxxxxxxx@out_E1_test:3] Set("SIP/2017-08c128c0", "~~EXTEN~~=017xxxxxxxx") in new stack
-- Executing [017xxxxxxxx@out_E1_test:4] Goto("SIP/2017-08c128c0", "sw-13-2017|10") in new stack
-- Goto (out_E1_test,sw-13-2017,10)
-- Executing [sw-13-2017@out_E1_test:10] Goto("SIP/2017-08c128c0", "sw-13-209|10") in new stack
-- Goto (out_E1_test,sw-13-209,10)
-- Executing [sw-13-209@out_E1_test:10] NoOp("SIP/2017-08c128c0", "caller is 200 ... 259 or 2000 ... 2059") in new stack
-- Executing [sw-13-209@out_E1_test:11] Set("SIP/2017-08c128c0", "NEWCLID="17"") in new stack
-- Executing [sw-13-209@out_E1_test:12] Goto("SIP/2017-08c128c0", "_XXXX.|5") in new stack
-- Goto (out_E1_test,_XXXX.,5)
-- Executing [_XXXX.@out_E1_test:5] NoOp("SIP/2017-08c128c0", "Finish switch-out_E1_test-13") in new stack
-- Executing [_XXXX.@out_E1_test:6] Set("SIP/2017-08c128c0", "CLID="xxxxxxx17"") in new stack
-- Executing [_XXXX.@out_E1_test:7] NoOp("SIP/2017-08c128c0", "Caller id is: xxxxxxx17") in new stack
-- Executing [_XXXX.@out_E1_test:8] Set("SIP/2017-08c128c0", "CALLERID(num)=xxxxxxx17") in new stack
-- Executing [_XXXX.@out_E1_test:9] SetCallerPres("SIP/2017-08c128c0", "allowed_passed_screen") in new stack
-- Executing [_XXXX.@out_E1_test:10] NoOp("SIP/2017-08c128c0", "dialing ZAP/g0/017xxxxxxxx| dpnumber | dpname ") in new stack
-- Executing [_XXXX.@out_E1_test:11] Dial("SIP/2017-08c128c0", "ZAP/g0/017xxxxxxxx") in new stack
-- Requested transfer capability: 0x00 - SPEECH
-- Called g0/017xxxxxxxx

The problem is that original extension 017xxxxxxxx@out_E1_test is replaced with _XXXX.@out_E1_test! So what seems single extension in AEL:

context out_E1_test {

        // This is an outgoing connection - 5 digits
        _XXXX. => {
                // Store CallerID in a variable to have it available with shorter name
                CLID = "${CALLERID(num)}";

                NoOp(Outgoing from ${CALLERID(num)} to ${EXTEN}, determining proper caller id...);
                switch (${CLID}) {
                        // numbers 2xxx: 2000 ... 2059
                        // numbers  2xx:  200 ...  259
                        // new CLID becomes xx (last 2 digits)
                        pattern 20[0-5]x:
                        pattern 2[0-5]x:
                                NoOp(caller is 200 ... 259 or 2000 ... 2059);
                                NEWCLID="${CLID:-2}";
                                break;

                        // numbers 2xxx: 2060 ... 2099
                        // numbers  2xx:  260 ...  299
                        // new CLID becomes 2xx (2 and last 2 digits)
                        pattern 20[6-9]x:
                        pattern 2[6-9]x:
                                NoOp(caller is 260 ... 299 or 2060 ... 2099);
                                NEWCLID="2${CLID:-2}";
                                break;

                        // number 2xxx: 2100 ... 2999
                        pattern 2zxx:
                        default:
                                NoOp(caller is 2100 ... 2999 or unknown);
                                NEWCLID={$CLID};
                                break;

                }
                CLID="${CLIDBASE}${NEWCLID}";
                NoOp(Caller id is: ${CLID});
                Set(CALLERID(num)=${CLID});
                SetCallerPres(allowed_passed_screen);
                Dial(${SANGOMA}/${EXTEN});
                Hangup;
        }
};

in fact becomes many extensions that end up with changing dst posted in cdr!

How can I prevent this from happening?