Implement ranking algorithm