added Z alorithm