Optimizing with lambda expressions and threaded streams in AI classes