Car Rev/Disconnected Piece?

#1
E6F25CE7-FB87-481E-8A25-37DC192B6373.jpeg 67328B7D-30C2-41A2-9B7B-94B65E856FCC.jpeg 08CA2D7A-F127-44B0-93E7-C1DD55F11A1A.jpeg 1717DF4A-31A1-43B6-B25A-8E4B478B3A33.jpeg Hi, recently purchased a 2004 toyota corolla with 150,000 miles. I looked in the hood and noticed recently there was a piece disconnected and I am unsure of what it is? Also, my car has been reving itself sometimes (not all the time) i usually notice it after it’s been sitting for a while. It only happens really when it’s in drive and i’m sitting at a light sometimes. I am thinking it could be an O2 Sensor problem (mass air flow intake problem?) or a vacuum leak? It tries to put itself in 2nd gear in the morning when I first start it, but after I shift to drive, there is no problem. If anyone has an idea or can help it would be greatly appreciated. Sorry if what I have described doesn’t make sense (i don’t know too much about cars). Thanks! Have a blessed day. (I have attached pictures of the piece I was referring to at the beginning).
 
#2
Where does that hose lead to? I'm guessing it's an air intake. Have you checked your air filter lately? Dirty air filters will do a number on your engine performance.
 
Top