modified balance function to pass style checker