borrowed from funtx:chars function