js error fix for sorting