added bigram and trigram functionality and cleaned up code