Modified after testing the code blocks inside, to make an better example