Fix table sorting bug