refactored the snippets code to make it an independent macro