Bug fixes to detokenization