improved algorithm of sequence building