Remove when.chain usages
Fix unit test