speed up expression tokenizing and optimize function