threaded version that mostly works - hangs occasionally and breaks with UTF-8 characters