Refactoring for base.Instances

Refactored the algorithm to use base.Instances. Rewrote the Fit method
to pre-calculate priors and conditional probabilities.