Refactor for new response envelope and refs