Merge https://gist.github.com/6617248 into shiva-persist-api
Putting all the bits of the original gist in the right places.