Changed all the callbacks into promises