Improved ranking javascript

Looking to merge it in to start fixes from a fresh basis.