finished KL divergence code