Refactored Promise implementaion with more features and robustness

Tested with unit tests - not with actual running project. Please verify that it works.