Fix unicode handling and use isinstance.