Added table sort function