fix settlement algorithm