tried to optimize almost sorted and cover stains