Added sort handling in JS