What happens when a butterfly under goes metamorphosis?

This would also apply to moths, by the way. The basic order is egg, larva (worm), pupa, chrysalis, cocoon, and then finally adult.