calculating balance