enclose value of context and self in closure instead of direct access to instance fields
optimize imports + format code
in case of failure it is possible to get 'Promise already complete', fixing that