balancing - working code