code to implement kf