Fix a bug in the bag of words code