Refactor promise chain into a separated file