[IMP]improve the ranking function and some code