Refactor TaskManager.swift