updated to handle utf-8 output