Function for balancing classes