Moving ranking logic to front end to reduce dependence on database, plus more cleanup.