Refactor Promise implementation and add tests
Correct whitespace