Remove when.chain usages
Fix unit test
Merge master