z-algo with bugs