added pack and unpack functions to flatten view models into objects that can be JSONified.