working on a better deferred promise code