Use OfType instead of Cast in a few places