Ensures that invalid characters are replaced