fix balancing with ties