refactored from old threading constructs to Task