Replace when.chain as it's deprecated