added table sorting js and fixed minor bugs