Correctly implement `balanced`.

Closes #395.