avoided log(small positive number)=-inf; fixed some bugs which arose from hard-coded constants