     declare v_substr_length int unsigned default 0;
     set @_wrap_select_num_original_columns := 0;
     
-my_main: begin
+    my_main: begin
     -- part one: find the SELECT keyword.
     my_loop: repeat 
         set v_old_from = v_from;

        ;
    end while;

    end;
    
    set p_text= concat(
                    v_statement

                -- check if we have multiple separated tokens
                if character_length(v_prev_tokens) - character_length(replace(v_prev_tokens, v_token_separator, '')) > 1 then
                    -- store the 2nd last token in v_handle
                    set v_handle = substring_index(substring_index(v_prev_tokens, v_token_separator, -2), v_token_separator, 1)
                    -- get the max length of the column expression
                    ,   v_substr_length = character_length(v_expression)
                    -- substract length that makes up the alias (and AS keyword if applicable)
                    ,   v_substr_length = v_substr_length - case 
                            when v_handle = 'AS' then    -- handle indicates an explicit alias.
                                2 + character_length(substring_index(v_expression, 'AS', -1))
                            when coalesce(v_handle, '') not in (  -- if the handle is not a keyword then the last token must be an alias. chop it off 
                                '', 'AND', 'BINARY', 'COLLATE', 'DIV', 'ESCAPE', 'LIKE', 'MOD', 'NOT'
                            ) and not (   -- what also counts as a keyword is a character set specifier. consider moving this into the tokenizer.
                                    v_handle = '_bin' 
                                or  v_handle LIKE '_%'
                                and exists (
                                    select  null 
                                    from    information_schema.character_sets 
                                    where   character_set_name = substring(v_handle, 2)
                                )
                            ) then
                                1+character_length(substring_index(v_prev_tokens, v_token_separator, -1))
                            else 0
                        end
                    -- chop off the alias.
                    ,   v_expression = substring(v_expression, 1, v_substr_length)
                    ;
                end if;
                
                set v_statement = concat(
