changed to use log probabilities