refactoring for contig-loop