takeSnapshot function.