refactored using promise like structure