some refactoring and adjustment to Navie Bayes