completed naive bayes implementation