add code snippets and explanation