refactored, and new tests for balance operation