Path tokenization function reimplementation. Some small changes