bug fix and added logsumexp