Fix the auto balancing and several other bugs