Refactor Promise implementation and add tests