Refactor subtask creation to be more general.