fixed messy balanced classify code