refactor using Q (promise)