invoke in separate thread.
clean up some threading code
small formatting updates