MOD: refactor FlattenTask.