use unicode:characters_to_binary instead of list_to_binary
refactor, rare using of lists:flatten and unicode:characters_to_binary