fix memory leakage of variable token
fix memory leakage of variable p
remove trailing blank spaces