added ability to handle chains with holes
spaghetti code ready for refactoring