     
     func entry(_ state: AATStateMachineState, _ klass: AATStateMachineClass) -> Entry? {
         
+        guard 0..<nClasses ~= klass.rawValue else { return nil }
+        
         let stateIdx = Int(state.rawValue) * Int(nClasses) + Int(klass.rawValue)
         var state = stateHeader.stateArray.dropFirst(stateIdx << 1)
         guard let entryIdx = try? Int(state.decode(BEUInt16.self)) else { return nil }

        var state = AATStateMachineState.startOfText
        guard var context = try? Context(self) else { return glyphs }
        
        func _perform(_ index: Int, _ glyph: Int?, _ klass: AATStateMachineClass) -> Bool {
            
            guard 0..<nClasses ~= klass.rawValue else { return false }
            
            var dont_advance = false
            var counter = 0
            
            repeat {
                
                guard counter < 0xFF else { return false }  // break infinite loop
                guard let entry = self.entry(state, klass) else { return false }
                
                guard context.transform(index, glyph, entry, &buffer) else { return false }
                
                dont_advance = entry.flags & 0x4000 != 0
                state = AATStateMachineState(rawValue: UInt16(entry.newState))

                counter += 1
                
            } while dont_advance
        }
        
        return buffer
