Refactoring + tests

Simplified chain.