refactory of TaskManager