add protection for log(0)