Hotfix for #5772: token processor should not cast booleans to strings

Hotfix for #5772

Also includes cleanups and stripping empty string replacements.