Fixed table sort and other bugs