Refactored Promise implementaion with more features and robustness