finished the snapshot algorithm