refactor flow around api response