Correctly parse HTML entities and more efficient index replacing