changed balance function logic