Added ranking tables, generalized a lot of code