added probabilities and did some refactoring