Table sorter and some cleanups