Fixed the "imbalance" and “out-of-bounds” errors.