New improved example

Revised to use function