Improved task scheduling and threads