
At different levels of temperature (ie energy), molecules of the body are moving at speeds proportional to the level of energy, so that, for example, when the water heats, its molecules moving increasingly fast, at some point (boiling point), the molecules tend to separate because its moving is fast, and therefore the water changes phase and is turn into vapor.
Instead, when you go removing energy (cools) of the body the molecules are moving ever more slowly, in the example of water, when we cooled, the molecules begin to lose energy (kinetic energy, ) and when you reach a certain point, the water begins to solidify, this because the molecules have so few kinetic energy, that can not overcome the intermolecular attractive forces, and begin to form crystal lattices, so ice crystals form . But even in that state, water molecules keeps some movement, and of course even vibrate, this because they are not withdrawn all the energy they possess.