minor changes
rearrange the adjustment for zero-probability to minimize
it effects in the derivative calculation