Refactoring balance code in views; adding tests