fixed the error in KL function