Heavily changed thread internal code (api is same) Fixed #3