implement bagofwords