Updated javascript for table sorting