Documenting and improving write_chr() function