Fix kp_id comparing bug, add some tests