fix bug when calculating end-score