first try to code the intra chain algorithm