js error fixes while sorting