improve tie breaking algorithm