Put JSON.parse/stringify in a function for clarity

The JSON.stringify/parse is a neat way to deep copy a data object, but it isn't apparent at first glance what it's for. So I moved the code into a function to better document its purpose.