Fixed value encoding issue. Can't wait for Py3 to become more widespread
added thread waiting