Refactored task factory to delegate creation to a lambda supplier.