Move replace function into tokens module