Added the code from SE page to task 2