finish ranking function
merge ranking algorithm