Tweaked calculateBalance