refactor using promises