Bugfixes and infinite loop detection

There is now a maximum on the number of snapshots to be able to detect
infinite loops.  The pointer to the latest snapshot is now removed when the
last snapshot is removed.