Improved example

Removed duplicate code by calling the function from within the function (thanks to suggestion in reddit comment)