Implemented ranking algorithm and added test