Refactor active task calculation