Saving state before refactoring.
Refactored promises a bit.
Handle if promise resolved with itself.
Promise resolved should resolve with same value.
Removed debug code. Added message to error.