Fix .replace function

Had a few JS errors.