Example code from class, conversion of code by @cenkayberkin