Lot's of these here. I feel like you can try to have Promise as the basic building block. saveKeyValues could return promise. Then you can return promise from promise onFulfilled and so on. Hadn't enough time to analyse it but you can have a look from this perspective.