Migrating derivation logic from Stream into Derivation.