Finished implementing the ranking algorithm