Simplify chain iterator, fix bug and cover it by tests