added table sorting, fixing pagination