Refactoring using deferreds.