UTF-8 support and fixing error handling in threads