Implement leaderboard feature

This PR contains all the changes from #466 and #575 , updated with the latest master and squashed to a single commit.