Made table sorting more generic