fix token replacement bug