code cleanup and refactored the snippets into different files