fix calculating of balance
clean up