Updated sordBy method using Sequence and generator