Improved array balancing. Fixes #48.