updated the algorithm for signature decoding