inter chain algorithme first try (need to debug it)