updated balance function