reorganize code using  deferred objects to eliminate nested call backs.
reorganize code using  deferred objects to eliminate nested call backs.