More bugs in replace_illegal_chars