Fix sorting and added k-limit