rewrote longestseq