Fixed sorting code in js.