Persistence

Merge a slightly modified version of the persistence patch.