changed to blocking model and improved threading code.