Great example! That is called selection! Natural, but in this case artificial selection. Organisms do not change because of the environment, that theory is wrong and called Lamarkism, not Darwinism. Neo-Darwinism (Darwinism + Genetics) speaks about selection. All of us got different variation of genes, which are quite stable, mutations are quite rare and they often useless or fatal, but some of them usefull. Anyhow, when cadmium did not exist, all worms were OK, but they some of them had genes of cadmium-resistence. Then environment changed and here we go, all useless (from evolution point of view) in current situation organisms died but those who had "right" genes survived. Look at Giraffes. Long ago they had normal necks. Let's say that 1% of them had slightly longer neck, guess what? They manage to get leaves better then other. They had higher chances to survive. So in several generations those with longer necks survived. Then it goes futher, out of them who had even longer necks survived. Etc. Looks simple, but it is complecated at the same time. Because long neck creates other comlecations for the organism. So out of longer neck giraffes survive those organism who had possibility to deal with high blood pressure etc. Evolution selects by many factors. Look at cars. Lets say there is an almost perfect car, powerful engine, great milage, great design, but horrible brakes? Who is going to buy that? Nobody. That car does not survive. People select cars which better value for a buck but with all needed stuff. Manufacturers of wrong cars do not survive, like many eastereropean manufacturers of cars disappeared.