modified tokenize function, and finding dummy end activity