Question: Ppossible Issue with Seq

I am trying to work through an example in a textbook, but its a few years old and uses maple 2015. I am currently using the 2018 edition of maple. The code is an example of how to generate the points on an elliptic curve given a specific input. 
Here is the example code from the textbook:

epoints := proc(ec, x, ub, p)
    local ecurve, z, pct, k, i;
    pct := 0;
    for k from 0 to p-1 while pct <= ub do
        z := subs(x=k, ec) mod p;
        if z = 0 then
           pct := pct+1;
           ecurve[pct] := [k,z];
        fi:
        if z &^ ((p-1)/2) mod p = 1 then
           z := z &^ ((p+1)/4) mod p;
           ecurve[pct+1] := [k,z];
           ecurve[pct+2] := [k, -z mod p];
           pct := pct+2;
        fi:
    od:
    if pct > ub then
       pct := ub:
    fi:
    seq(ecurve[i], i=1..pct):
end:


Here is my code, written to work with Maple 2018:

ecpoints := proc (ec, x, ub, p) local ecurve, z, pct, k, i;
      pct := 0; for k from 0 to p-1 while pct <= ub
         do z := `mod`(subs(x = k, ec), p);
         if z = 0 then pct := pct+1;
            ecurve[pct] := [k, z] end if;
         if `mod`(z^((1/2)*p-1/2), p) = 1 then
            z := `mod`(z^((1/4)*p+1/4), p) = 1;
           ecurve[pct+1] := [k, z];
           ecurve[pct+2] := [k, `mod`(-z, p)];
           pct := pct+2 end if
   end do;
   if ub < pct then pct := ub end if;


   seq(ecurve[i], i = 1 .. pct)
end proc

The problem is with the output. The output should be [0, 5], [0, 14], [2, 4], [2, 15], [3, 6], [3, 13], [4, 6], [4, 13], [6, 0], [10, 16], [10, 3], [12, 6], [12, 13], [14, 16], [14, 3], [18, 17], [18, 2].
What I get is [0, 5 = 1], [0, 14 = 18], [2, 4 = 1], [2, 15 = 18], [3, 6 = 1], [3, 13 = 18], [4, 6 = 1], [4, 13 = 18], [6, 0], [10, 16 = 1], [10, 3 = 18], [12, 6 = 1], [12, 13 = 18], [14, 16 = 1], [14, 3 = 18], [18, 17 = 1], [18, 2 = 18]. 
Any hints on what I could be doing wrong here or what is going on?

Please Wait...