Improve chains handling

This PR fixes chains handling, they now work as expected.