modified for Unicode support