fix bugs for cosign

1) Put requires use of new operator, 2) replace negative indexes with len-n.