Refactored the snippet and added an example of usage.