I suppose you could factor all that into the model, though I'd question the feasibility of doing so.
I'd also argue that grades aren't the only important factor in schooling. Building social skills, discipline, time management, helping to realize goals... All ways in which good teachers can influence students, and only some of them reflect in neat packages like test scores.
Edit: I'd like to clarify that in my previous post I mentioned getting more difficult classes sometimes as the luck of the draw. I didn't mean low ability classes. I meant classes with students with serious behavioral issues, students with learning disabilities and so on. These will very often negatively impact the learning outcomes of the entire class, and is something you very rarely if ever have to deal with in top end classes.