added kp algorithm