might be worth extracting this method out into utils.js