fix token parsing and unparsing