This functionality should go into `api.js`