Improved task sort