Dynamics of entanglement