I think I have all the ranking functions declared now, I just need to sort the groups and it should be finished.