Replaced prevState visibility checking with a generic Control foreach loop.