cleaned up sorting on tables