refactoring using promises