update the KL methods for robustness and fix a bug found in Coverity Scan