refactoring with q promises