Improved API. Basic thread loop.